#include <stdio.h>
#include <vector>
using namespace std;

long long gcd(int A, int B) {
    long long a = A;
    long long b = B;
    long long r;
    do {
        r = a % b;
        long long q = a / b;
        a = b;
        b = r;
    } while(r);
    return a;
}

long long lcm(long long a, long long b) {
    return (a*b) / gcd(a,b);
}

long long lcm(const vector<int>& nums) {
    const size_t cnt = nums.size();
    long long res = nums[0];
    for (size_t i = 1; i < cnt; ++i)
        res = lcm(res, nums[i]);
    return res;
}

int main() {
    int N = 0;
    scanf("%d", &N);

    vector<int> p(N+1);
    for (int i = 1; i <= N; ++i)
        scanf("%d", &p[i]);

    vector<int> periods(N);
    for (int i = 1; i <= N; ++i) {
        int t = 1;
        for (int tmp = p[i]; tmp != i; ++t)
            tmp = p[tmp];
        periods[i-1] = t;
    }

    int res = lcm(periods);
    printf("%d\n", res);
    return 0;
}

